<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2018\10\28 0028
 * Time: 10:03
 */
namespace app\admin\model;
use think\Db;

class Danb
{
    /**查看单表数据
     * @param $id:单表id
     * @return array
     */
    public static function show($id){
        $model = Db::name('model')->where('id',$id)->find();
//        return $model;
        $array = Db::name($model['surface'])->select();
        $field = Db::name('table_field')->where('modelid',$id)->select();
        $head  = '<tr>
				<th scope="col" colspan="'.(count($field)+3).'">'.$model['model_name'].'列表</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th >ID</th>';
//        echo '<pre>';
//        print_r($field);exit;
        foreach ($field as $value){
            $head .= '<th>'.$value['field_name'].'</th>';
        }
        $head .='<td>操作</td></tr>';
        $tbody = '';
        foreach ($array as $value){
            $tbody .='<tr class="text-c">
				<td><input type="checkbox" value="'.$value['id'].'" name="userid"></td><td>'.$value['id'].'</td>';
            foreach ($field as $va){
                if($va['field_type']=='单行文本'){
                    $tbody .= '<td>'.$value[$va['field_title']].'</td>';
                }elseif($va['field_type']=='时间'){
                    $tbody .= '<td>'.date("Y-m-d H:i:s",$value[$va['field_title']]).'</td>';
                }elseif($va['field_type']=='多行文本'){
                    $tbody .= '<td>'.$value[$va['field_title']].'</td>';
                }elseif($va['field_type']=='单文件'){
                    if($value[$va['field_title']]){
                        $tbody .= '<td>'.$value[$va['field_title']].'</td>';
                    }else{
                        $tbody .= '<td></td>';
                    }
                }elseif($va['field_type']=='单图片'){
                    if($value[$va['field_title']]){
                        $tbody .= '<td><img src="'.$value[$va['field_title']].'" width="50"/></td>';
                    }else{
                        $tbody .= '<td></td>';
                    }
                }elseif($va['field_type']=='多文件'){
                    if($value[$va['field_title']]&&count(json_decode($value[$va['field_title']],true))){
                        $haha = json_decode($value[$va['field_title']],true);
                        $tbody .= '<td>';
                        foreach ($haha as $i){
                            $tbody .= $i.',';
                        }
                        $tbody .= '</td>';
                    }else{
                        $tbody.='<td></td>';
                    }
                }elseif($va['field_type']=='多图片'){
                    if($value[$va['field_title']]&&count(json_decode($value[$va['field_title']],true))){
                        $haha = json_decode($value[$va['field_title']],true);
                        $tbody .= '<td>';
                        foreach ($haha as $i){
                            $tbody .= '<img src="'.$i.'" width="50"/>';
                        }
                        $tbody .= '</td>';
                    }else{
                        $tbody.='<td></td>';
                    }
                }elseif ($va['field_type']=='单选框'){
                    $tbody .= '<td>'.$value[$va['field_title']].'</td>';
                }elseif ($va['field_type']=='复选框'){
                    $tbody .='<td>';
                    if($value[$va['field_title']]&&count(json_decode($value[$va['field_title']],true))){
                        $haha = json_decode($value[$va['field_title']],true);
                        foreach ($haha as $i){
                            $tbody .= $i.',';
                        }
                    }
                    $tbody .= '</td>';
                }elseif ($va['field_type']=='下拉框'){
                    $tbody .='<td>'.$value[$va['field_title']].'</td>';
                }elseif ($va['field_type']=='编辑文本'){
                    $tbody .= '<td>'.$value[$va['field_title']].'</td>';
                }
            }
            $tbody.='<td class="td-manage">'.
                    '<a title="编辑" href="javascript:;" onclick="articlecon_edit(\'编辑\',\'/admin/danbiao/edit?id='.$value["id"].'&modelid='.$id.'\',800,700)" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>
<a title="删除" href="javascript:;" onclick="del(this,\''.$value['id'].'\',\''.$model['id'].'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
</tr>';
        }
        //return $field;
        return ['head'=>$head,'tbody'=>$tbody];
    }

    /**加载单表添加页面
     * @param $id
     * @return string
     */
    public static function show_add($id){
        $feild = Db::name('table_field')->where('modelid',$id)->select();
        $str = '';
        foreach ($feild as $value){
            //单行文本添加
            if ($value['field_type'] == '单行文本') {
//                echo '<pre>';
//                print_r($value);exit;
                if ($value['type_status'] == 1) {
//                    return 12;exit;
                    $str .= '<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">
			<span class="c-red">*</span>' . $value['field_name'] . '：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" >
		</div>
	</div>';
                }
                //多行文本添加
            }elseif ($value['field_type'] == '时间') {
//                echo '<pre>';
//                print_r($value);exit;
                if ($value['type_status'] == 1) {
//                    return 12;exit;
                    $str .= '<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">
			<span class="c-red">*</span>' . $value['field_name'] . '：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" >
		</div>
	</div>';
                }
                //多行文本添加
            } elseif ($value['field_type'] == '多行文本') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="' . $value['field_title'] . '" id="' . $value['field_title'] . '" style="width: 100%;height: 100px"></textarea>
			</div>
		</div>';
                }
                //单文件
            } elseif ($value['field_type'] == '单文件') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" onchange="yulan(this)">点击预览
				</div>
			</div>
		</div>';
                }
                //多文件
            } elseif ($value['field_type'] == '单图片') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" onchange="yulan(this)">点击预览
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片预览：</label>
			<div class="formControls col-xs-8 col-sm-9 show">
				
			</div>
		</div>';
                }
                //多文件
            }elseif ($value['field_type'] == '视频') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" onchange="yulanshipin(this)">点击预览
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片预览：</label>
			<div class="formControls col-xs-8 col-sm-9 show">
				
			</div>
		</div>';
                }
                //多文件
            }elseif ($value['field_type'] == '多文件') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '[]" onchange="yulan(this)" multiple>点击预览
				</div>
			</div>
		</div>';
                }
                //单选框
            } elseif ($value['field_type'] == '多图片') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '[]" onchange="yulan(this)" multiple>点击预览
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片预览：</label>
			<div class="formControls col-xs-8 col-sm-9 show">
				
			</div>
		</div>';
                }
                //单选框
            }elseif ($value['field_type'] == '单选框') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>'.$value['field_name'].'：</label>
			<div class="formControls col-xs-8 col-sm-9">';
                    if ($value['type_option']) {
                        $array = explode(',', $value['type_option']);
                        foreach ($array as $values) {
                            $str .= '<input type="radio" name="'.$value['field_title'].'" value="'.$values . '">'.$values;
                        }
                    }

                    $str .= '</div>
		</div>';
                }
                //复选框
            }elseif ($value['field_type'] == '复选框'){
                if ($value['type_status'] == 1) {
                    $str .='<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>'.$value['field_name'].'：</label>
			<div class="formControls col-xs-8 col-sm-9">';
                    if ($value['type_option']) {
                        $array = explode(',', $value['type_option']);
                        foreach ($array as $values) {
                            $str .= '<input type="checkbox" name="'.$value['field_title'].'[]" value="' . $values . '">' . $values;
                        }
                    }

                    $str .= '</div>
		</div>';
                }
                //下拉框
            }elseif ($value['field_type'] == '下拉框'){
                if ($value['type_status'] == 1) {
                    $str .='<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>'.$value['field_name'].'：</label>
			<div class="formControls col-xs-8 col-sm-9"><select name="'.$value['field_title'].'">';
                    if ($value['type_option']) {
                        $array = explode(',', $value['type_option']);
                        foreach ($array as $values) {
                            $str .= '<option value="'.$values.'">'.$values.'</option>';
                        }
                    }

                    $str .= '</select></div>
		</div>';
                }
                //编辑文本
            }elseif($value['field_type'] == '编辑文本'){
                if ($value['type_status'] == 1) {
                    $str .='<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">
			<span class="c-red">*</span>' . $value['field_name'] . '：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<script id="editor" type="text/plain" name="'.$value['field_title'].'" style="width:100%;height:500px;"></script>
		</div>
	</div>';
                }
            }
        }
        return $str;
    }

    /**向单表添加数据
     * @param $data：数据
     * @param $file：文件
     * @return bool
     */
    public static function add_d($data,$file){
//        return $data;
        $modelid = $data['modelid'];
        $field = Db::name('table_field')->where('modelid',$modelid)->select();
        foreach ($field as $value){
            if($value['field_type']=='单行文本'){
                $data[$value['field_title']] = $data[$value['field_title']];
            }elseif($value['field_type']=='时间'){
                $data[$value['field_title']] = strtotime($data[$value['field_title']]);
            }elseif ($value['field_type']=='多行文本'){
                $data[$value['field_title']] = $data[$value['field_title']];
            }elseif ($value['field_type']=='单文件'){
                if(isset($file[$value['field_title']])){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if($img){
                        $data[$value['field_title']] = $img;
                    }
                }
            }elseif ($value['field_type']=='单图片'){
                if(isset($file[$value['field_title']])&&$file[$value['field_title']]){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if($img){
                        $data[$value['field_title']] = $img;
                    }
                }
            }elseif ($value['field_type']=='视频'){
                if($file[$value['field_title']]){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if($img){
                        $data[$value['field_title']] = $img;
                    }
                }
            }elseif($value['field_type']=='多文件'){
                if(isset($file[$value['field_title']])){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if($img){
                        $data[$value['field_title']] = json_encode($img);
                    }
                }

            }elseif($value['field_type']=='多图片'){
                if(isset($file[$value['field_title']])){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if($img){
                        $data[$value['field_title']] = json_encode($img);
                    }
                }

            }elseif($value['field_type']=='单选框'){
                if(isset($data[$value['field_title']])){
                    $data[$value['field_title']] = $data[$value['field_title']];
                }
            }elseif ($value['field_type']=='复选框'){
                if(isset($data[$value['field_title']])){
                    $data[$value['field_title']] = json_encode($data[$value['field_title']]);
                }
            }elseif ($value['field_type']=='下拉框'){
                $data[$value['field_title']] = $data[$value['field_title']];
            }elseif ($value['field_type']=='编辑文本'){
                if(isset($data[$value['field_title']])){
                    $data[$value['field_title']] = $data[$value['field_title']];
                }
            }
        }
        unset($data['modelid']);
        $surface = (Db::name('model')->where('id',$modelid)->find())['surface'];
//        return $data;
        if(Db::name($surface)->insert($data)){
            return true;
        }else{
            return false;
        }
    }

    /**编辑单表数据
     * @param $id:数据id
     * @param $modelid：模型id
     * @return string
     */
    public static function edit_d($id,$modelid){
        $model = Db::name('model')->where('id',$modelid)->find();
        $shuju = Db::name($model['surface'])->where('id',$id)->find();
        $feild = Db::name('table_field')->where('modelid',$modelid)->select();
        $str = '<input type="text" name="id" value="'.$id.'" style="display:none"/><input type="text" name="modelid" value="'.$modelid.'" style="display:none"/>';
        foreach ($feild as $value){
            if ($value['field_type'] == '单行文本') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">
			<span class="c-red">*</span>' . $value['field_name'] . '：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="' . $shuju[$value['field_title']] . '" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" >
		</div>
	</div>';
                }
                //多行文本添加
            }elseif ($value['field_type'] == '时间') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">
			<span class="c-red">*</span>' . $value['field_name'] . '：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="' . date('Y-m-d H:i:s',$shuju[$value['field_title']]) . '" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" >
		</div>
	</div>';
                }
                //多行文本添加
            } elseif ($value['field_type'] == '多行文本') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="' . $value['field_title'] . '" id="' . $value['field_title'] . '" style="width: 100%;height: 100px">' . $shuju[$value['field_title']] . '</textarea>
			</div>
		</div>';
                }
                //单文件
            } elseif ($value['field_type'] == '单文件') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" onchange="yulan(this)">点击预览
				</div>
			</div>
		</div>';
                }
                //多文件
            }elseif ($value['field_type'] == '多文件') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '[]" onchange="yulan(this)" multiple>点击预览
				</div>
			</div>
		</div>';
                }
                //单选框
            } elseif ($value['field_type'] == '多图片') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '[]" onchange="yulan(this)" multiple>点击预览
				</div>
			</div>
		</div>';
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片预览：</label>
			<div class="formControls col-xs-8 col-sm-9 show">';
                    if($shuju[$value['field_title']]&&count(json_decode($shuju[$value['field_title']],true))){
                        foreach (json_decode($shuju[$value['field_title']],true) as $va){
                            $str .='<img src="'.$va.'" width="100px"/>';
                        }
                    }
                    $str .= '</div>
		</div>';
                }
                //单选框
            } elseif ($value['field_type'] == '单图片') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" onchange="yulan(this)">点击预览
				</div>
			</div>
		</div>';
                    if($shuju[$value['field_title']]){
                        $str .='<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片预览：</label>
			<div class="formControls col-xs-8 col-sm-9 show">
				<img src="'.$shuju[$value['field_title']].'" width="100"/>
			</div>
		</div>';
                    }else{
                        $str .='<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片预览：</label>
			<div class="formControls col-xs-8 col-sm-9 show">
				
			</div>
		</div>';
                    }
                }
                //多文件
            }elseif ($value['field_type'] == '视频') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>' . $value['field_name'] . '：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="file">
					<input type="file" id="' . $value['field_title'] . '" name="' . $value['field_title'] . '" onchange="yulanshipin(this)">点击预览
				</div>
			</div>
		</div>';
                    if($shuju[$value['field_title']]){
                        $str .='<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>视频：</label>
			<div class="formControls col-xs-8 col-sm-9 show">
				<video src="'.config('fuwuqi').'/'.$shuju[$value['field_title']].'" controls="controls" style="width: 50%">
您的浏览器不支持 video 标签。
                    </video>
			</div>
		</div>';
                    }else{
                        $str .='<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片预览：</label>
			<div class="formControls col-xs-8 col-sm-9 show">
				
			</div>
		</div>';
                    }
                }
            } elseif ($value['field_type'] == '单选框') {
                if ($value['type_status'] == 1) {
                    $str .= '<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>'.$value['field_name'].'：</label>
			<div class="formControls col-xs-8 col-sm-9">';
                    if ($value['type_option']) {
                        $array = explode(',', $value['type_option']);
                        foreach ($array as $values) {
                            if($shuju[$value['field_title']]==$values){
                                $str .= '<input type="radio" name="'.$value['field_title'].'" value="'.$values . '" checked>'.$values;
                            }else{
                                $str .= '<input type="radio" name="'.$value['field_title'].'" value="'.$values . '">'.$values;
                            }
                        }
                    }

                    $str .= '</div>
		</div>';
                }
                //复选框
            }elseif ($value['field_type'] == '复选框'){
                if ($value['type_status'] == 1) {
                    $str .='<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>'.$value['field_name'].'：</label>
			<div class="formControls col-xs-8 col-sm-9">';
                    if ($value['type_option']) {
                        $array = explode(',', $value['type_option']);
                        foreach ($array as $values) {
                            if($shuju[$value['field_title']]==$values){
                                $str .= '<input type="checkbox" name="'.$value['field_title'].'[]" value="' . $values . '" checked>' . $values;
                            }else{
                                $str .= '<input type="checkbox" name="'.$value['field_title'].'[]" value="' . $values . '">' . $values;
                            }

                        }
                    }

                    $str .= '</div>
		</div>';
                }
                //下拉框
            }elseif ($value['field_type'] == '下拉框'){
                if ($value['type_status'] == 1) {
                    $str .='<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>'.$value['field_name'].'：</label>
			<div class="formControls col-xs-8 col-sm-9"><select name="'.$value['field_title'].'">';
                    if ($value['type_option']) {
                        $array = explode(',', $value['type_option']);
                        foreach ($array as $values) {
                            if($shuju[$value['field_title']]==$values){
                                $str .= '<option value="'.$values.'" selected>'.$values.'</option>';
                            }else{
                                $str .= '<option value="'.$values.'">'.$values.'</option>';
                            }

                        }
                    }

                    $str .= '</select></div>
		</div>';
                }
                //编辑文本
            }elseif($value['field_type'] == '编辑文本'){
                if ($value['type_status'] == 1) {
                    $str .='<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">
			<span class="c-red">*</span>' . $value['field_name'] . '：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<script id="editor" type="text/plain" name="'.$value['field_title'].'" style="width:100%;height:500px;">'.$shuju[$value['field_title']].'</script>
		</div>
	</div>';
                }
            }
        }
        return $str;
    }

    /**更新单表数据
     * @param $data：数据
     * @param $file：文件
     * @return bool
     */
    public static function update_d($data,$file){
        $modelid = $data['modelid'];
        unset($data['modelid']);
        $field = Db::name('table_field')->where('modelid',$modelid)->select();
        $table = (Db::name('model')->where('id',$modelid)->find())['surface'];
        $shuju = Db::name($table)->where('id',$data['id'])->find();
        foreach ($field as $value){
            if($value['field_type']=='单行文本'){
                $data[$value['field_title']] = $data[$value['field_title']];
            }elseif($value['field_type']=='时间'){
                $data[$value['field_title']] = strtotime($data[$value['field_title']]);
            }elseif ($value['field_type']=='多行文本'){
                $data[$value['field_title']] = $data[$value['field_title']];
            }elseif ($value['field_type']=='单文件'){
                if(isset($file[$value['field_title']])){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if($img){
                        if($shuju[$value['field_title']]){
                            Qinu::DeleFile($shuju[$value['field_title']]);
                        }
                        $data[$value['field_title']] = $img;
                    }
                }
            }elseif ($value['field_type']=='单图片'){
                if(isset($file[$value['field_title']])){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if($img){
                        if($shuju[$value['field_title']]){
                            Qinu::DeleFile($shuju[$value['field_title']]);
                        }
                        $data[$value['field_title']] = $img;
                    }
                }
            }elseif ($value['field_type']=='视频'){
                if(isset($file[$value['field_title']])){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if($img){
                        if($shuju[$value['field_title']]){
                            Qinu::DeleFile($shuju[$value['field_title']]);
                        }
                        $data[$value['field_title']] = $img;
                    }
                }
            }elseif($value['field_type']=='多文件'){
                if(isset($file[$value['field_title']])){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if(count($img)){
                        if($shuju[$value['field_title']]&&count(json_decode($shuju[$value['field_title']],true))){
                            $j = json_decode($shuju[$value['field_title']],true);
                            foreach ($j as $v){
                                Qinu::DeleFile($v);
                            }
                        }
                        $data[$value['field_title']] = json_encode($img);
                    }
                }
            }elseif($value['field_type']=='多图片'){
                if(isset($file[$value['field_title']])){
                    $img = Qinu::Upfile($file[$value['field_title']]);
                    if(count($img)){
                        if($shuju[$value['field_title']]&&count(json_decode($shuju[$value['field_title']],true))){
                            $j = json_decode($shuju[$value['field_title']],true);
                            foreach ($j as $v){
                                Qinu::DeleFile($v);
                            }
                        }
                        $data[$value['field_title']] = json_encode($img);
                    }
                }
            }elseif($value['field_type']=='单选框'){
                if(isset($data[$value['field_title']])){
                    $data[$value['field_title']] = $data[$value['field_title']];
                }
            }elseif ($value['field_type']=='复选框'){
                if(isset($data[$value['field_title']])){
                    $data[$value['field_title']] = json_encode($data[$value['field_title']]);
                }
            }elseif ($value['field_type']=='下拉框'){
                $data[$value['field_title']] = $data[$value['field_title']];
            }elseif ($value['field_type']=='编辑文本'){
                if(isset($data[$value['field_title']])){
                    $data[$value['field_title']] = $data[$value['field_title']];
                }
            }
        }
        if(Db::name($table)->where('id',$data['id'])->update($data)){
            return true;
        }else{
            return false;
        }
    }

    /**删除单表数据
     * @param $id：表数据id
     * @param $modelid：模型id
     * @return bool
     */
    public static function delete($id,$modelid){
        $model = Db::name('model')->where('id',$modelid)->find();
        $field = Db::name('table_field')->where('modelid',$modelid)->select();
        $data  = Db::name($model['surface'])->where('id',$id)->find();
        foreach ($field as $value){
            if($value['field_type']=='单文件'){
                if($data[$value['field_title']]){
                    Qinu::DeleFile($data[$value['field_title']]);
                }
            }elseif($value['field_type']=='多文件'){
                if($data[$value['field_title']]&&count(json_decode($data[$value['field_title']],true))){
                    $arr = json_decode($data[$value['field_title']],true);
                    foreach ($arr as $va){
                        Qinu::DeleFile($va);
                    }
                }
            }elseif($value['field_type']=='多图片'){
                if($data[$value['field_title']]&&count(json_decode($data[$value['field_title']],true))){
                    $arr = json_decode($data[$value['field_title']],true);
                    foreach ($arr as $va){
                        Qinu::DeleFile($va);
                    }
                }
            }elseif($value['field_type']=='单图片'){
                if($data[$value['field_title']]){
                    Qinu::DeleFile($data[$value['field_title']]);
                }
            }elseif($value['field_type']=='视频'){
                if($data[$value['field_title']]){
                    Qinu::DeleFile($data[$value['field_title']]);
                }
            }
        }
        if(Db::name($model['surface'])->where('id',$id)->delete()){
            return true;
        }else{
            return false;
        }
    }
}